package com.ecar.api.support.util;

import net.sf.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import com.ecar.common.util.HttpClientUtil;

/**
 * Created by 30 on 2017/6/10.
 * Copyed by fire on 2017/11/15
 */
public class Helper {

	/**
	 * 上传头像
	 *
	 * @param avatar
	 * @return
	 */
	public static String uploadBase64Avatar(String avatar) {
		try {
			String host = Props.getValue("config.cos.url");
			String uri = "/up/avatar/b64?attributeName=avatar";
			String response = HttpClientUtil.httpPostContent(host+uri, avatar);
			JSONObject resp = JSONObject.fromObject(response);
			if (resp.containsKey("code") && resp.getInt("code") == 200) {
				return resp.getString("filePath");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
